package io.renren.modules.sjtixian.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;
import io.renren.modules.sjtixian.entity.SjTixianEntity;
import io.renren.modules.sjtixian.service.WebSjTixianService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;




/**
 * 司机提现表
 * 
 * @author wangdajiang
 * @email 2750757088@qq.com
 * @date 2018-04-19 14:10:58
 */
@RestController
@RequestMapping("/sjtixian")
public class SjTixianController {
	@Autowired
	private WebSjTixianService webSjTixianService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("sjtixian:list")
	public R list(@RequestParam Map<String, Object> params){
		String start =  String.valueOf(params.get("startCreateTime"));
		String end =  String.valueOf(params.get("endCreateTime"));
		if(start !=null &&  !"".equals(start) && !"null".equals(start)) {
			params.put("startCreateTime",start);
		}
		if(end !=null &&  !"".equals(end) && !"null".equals(end)) {
			params.put("endCreateTime",end);
		}
		//分页
        Query query = new Query(params);
		List<SjTixianEntity> sjTixianList = webSjTixianService.queryList(query);
		int total = webSjTixianService.queryTotal(query);
		PageUtils pageUtil = new PageUtils(sjTixianList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("sjtixian:info")
	public R info(@PathVariable("id") Long id){
		SjTixianEntity sjTixian = webSjTixianService.queryObject(id);
		
		return R.ok().put("sjTixian", sjTixian);
	}
	
	/**
	 * 审核保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("sjtixian:save")
	public R save(@RequestBody SjTixianEntity sjTixian){
		webSjTixianService.save(sjTixian);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("sjtixian:update")
	public R update(@RequestBody SjTixianEntity sjTixian){
		sjTixian.setIfExamine(1);
		webSjTixianService.update(sjTixian);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("sjtixian:delete")
	public R delete(@RequestBody Long[] ids){
		webSjTixianService.deleteBatch(ids);
		
		return R.ok();
	}
	
}
